#include "kernel/types.h"
#include "user.h"

int main() {
    int c2f[2];
    int f2c[2];
    int buf;
    pipe(c2f);
    pipe(f2c);
if (fork() == 0) { 
    /* 子进程 */
    read(f2c[0],&buf,1);
    printf("%d: received ping from pid %d\n",getpid(),buf);
    close(c2f[0]); 
    int cpid=getpid();
    write(c2f[1],&cpid,1); /* 向管道写入"hello world\n" */
    close(c2f[1]);                      /* 关闭管道的写端，表示写入完成 */
    exit(getpid());
} else {
    /* 父进程 */
    int fpid;
    fpid=getpid();  
    close(f2c[0]);                      /* 关闭管道的读端 */
    write(f2c[1],&fpid,1); /* 向管道写入"hello world\n" */
    close(f2c[1]);                      /* 关闭管道的写端，表示写入完成 */
    read(c2f[0],&buf,1);
    printf("%d: received pong from pid %d\n",getpid(),buf);
}
exit(0);
}